package com.gl.controller.admin;

import com.gl.pojo.Result;
import com.gl.pojo.dto.UserPageDto;
import com.gl.service.PermissionService;
import com.gl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
//@CrossOrigin("*")
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private UserService userService;

    @Autowired
    private PermissionService permissionService;

    /**
     * 管理员删除用户
     */
    @PostMapping("users/delete")
    public Result deleteUser(@RequestParam("id") String userId) {
        userService.deleteById(userId);
        return Result.success();
    }

    /**
     * 分页查询用户信息
     */
    @GetMapping("users/list")
    public Result listPage(UserPageDto userPage) {
        return Result.success(userService.page(userPage));
    }

    /**
     * 获取已审批的管理员申请列表
     */
    @GetMapping("permissions/reviewed")
    public Result reviewedPage(UserPageDto userPage) {
        return Result.success(permissionService.reviewedPage(userPage));
    }

    /**
     * 获取未审批的管理员申请列表
     * @param userPage
     * @return
     */
    @GetMapping("permissions/pending")
    public Result pendingPage(UserPageDto userPage) {
        return Result.success(permissionService.pendingPage(userPage));
    }

    /**
     * 提交审核结果
     * @param applicationId
     * @param status
     * @return
     */
    @PostMapping("permissions/approving")
    public Result approving(@RequestParam("key") Integer applicationId,
                            @RequestParam("status") String status) {
        permissionService.processApproval(applicationId, status);
        return Result.success();
    }

}
